package com.yeming.socket.utils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.*;
import java.util.Properties;

public class KafkaUtils {

    private static Logger logger = LogManager.getLogger(KafkaUtils.class.getName());

    public static Properties getSystemProp() {


        Properties sysProp = new Properties();

        File file = new File("config/producer.properties");
        InputStream in = null;
        if (!file.exists()) {
            file = new File("producer.properties");
        }
        if (!file.exists()) {
            return null;
        }

        try {
            logger.info(String.format("当前读取的系统配置文件路径: %s", file.getAbsolutePath()));
            in = new FileInputStream(file);
            sysProp.load(in);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            logger.error("配置文件没有找到！");
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("配置文件加载失败！");
            return null;
        }

        return sysProp;
    }
}
